package nl.foldervisualizer
/**
 * Author: Jamie Craane
 * Date: 5-jun-2008
 * Time: 21:17:19
 */
class FolderItem {
    String path
    double relativeSize
    long bytes

    public FolderItem(String path) {
        this.path = path
    }

    public FolderItem plus(FolderItem other) {
        return new FolderItem(this.path, this.relativeSize + other.relativeSize, this.bytes + other.bytes)
    }

    public FolderItem(String path, double relativeSize, long bytes) {
        this.path = path
        this.relativeSize = relativeSize
        this.bytes = bytes
    }

    public String getItemName() {
        String name = null;
        if(path.contains('\\')) {
            name = path.substring(path.lastIndexOf('\\') + 1)
        } else if(path.contains('/')) {
            name = path.substring(path.lastIndexOf('/') + 1) 
        }

        if(name?.size() > 20) {
            name = name.substring(0, 20) + '...'
        }
        return name != null ? name : path
    }
}